<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    #application {
      text-align: center;
    }
    .button {
      border-radius: 30px;
      width: 100px;
      margin: 20px auto;
      color: white;
      background-color: blue;
    }
  </style>
</head>
<body>
  <div id="application" v-cloak>
    <h1>{{title}}</h1>
    <!-- 账号密码 -->
    <div v-if="noLogin">
      <div>
        <span>账号：</span>
        <input type="text" v-model="userName">
      </div>
      <div>
        <span>密码：</span>
        <input type="password" v-model="password">
      </div>
    </div>
    <!-- 登录按钮 -->
    <div class="button" @click="handleClick">{{buttonTitle}}</div>
  </div>
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  <script>
    const App = {
      data() {
        return {
          title: '欢迎您，未登录',
          noLogin: true,
          userName: '',
          password: '',
          buttonTitle: '登录'
        }
      },
      methods: {
        handleClick() {
          if (this.noLogin) {
            this.doLogin()
          } else {
            this.doLogout()
          }
        },
        doLogin() {
          if (this.userName && this.password ) {
            this.noLogin = false
            this.title = '欢迎您，' + this.userName
            this.buttonTitle = '退出'
            this.userName = ''
            this.password = ''
          } else {
            alert('请输入账号和密码')
          }
        },
        doLogout() {
          this.noLogin = true
          this.title = '欢迎您，未登录'
          this.buttonTitle = '登录'
        }
      }
    }
    Vue.createApp(App).mount('#application')
  </script>
</body>
</html>